package com.panshi.controller;

import com.panshi.entity.AppMatterCheckT;
import com.panshi.result.R;
import com.panshi.service.QaClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class QaController {

    @Autowired
    private QaClientService qaClientService;

    @PostMapping("/qaAdd")
    @ResponseBody
    public R qaAdd(HttpServletRequest request){
        String title = request.getParameter("title");
        String content = request.getParameter("content");
        String essayimg = request.getParameter("essayimg");
        String classType = request.getParameter("classType");

        R r = new R();
        if(title==null || content ==null || classType == null){
            r.setCode(301);
            r.setSuccess(false);
            r.setMessage("请输入正确信息");
            return r;
        }
        String userId = request.getParameter("userId");
        if(userId==null){
            r.setCode(301);
            r.setSuccess(false);
            r.setMessage("登录已失效，请重新登录！！！");
            return r;
        }


        AppMatterCheckT matterCheckT = new AppMatterCheckT();
        matterCheckT.setUserId(Integer.valueOf(userId));
        matterCheckT.setMatterTitle(title);
        matterCheckT.setMatterContent(content);
        matterCheckT.setClassifyId(Integer.valueOf(classType));
        matterCheckT.setImgPath(essayimg);
        System.out.println("添加咨询");
        System.out.println(matterCheckT);

        Boolean aBoolean = qaClientService.setMatterCheckAdd(matterCheckT);
        if(aBoolean){
            r.setCode(201);
            r.setSuccess(false);
            r.setMessage("发表成功 等待审核");
            return r;
        }
        return R.error();
    }
}
